package com.example.project_dish.Dishes;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.project_dish.R;

import java.util.ArrayList;

public class RightFragment extends Fragment {

    private ArrayList<DishesDetail> dishesDetailArrayList = new ArrayList<>(); //右边菜品数据

    private View view;

    private View view1;

    private DishesDetailAdapter dishesDetailAdapter;

    /**
     * 绑定java类和碎片布局文件  fragment_right.xml
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //  根据布局文件去创建碎片的视频界面
        view = inflater.inflate(R.layout.fragment_right,container,false);
        view1 = inflater.inflate(R.layout.dishes_show, container, false);
//        Log.d("test1", String.valueOf(dishesDetailArrayList));
        dishesDetailAdapter = new DishesDetailAdapter(getContext(), R.layout.dishes_show, dishesDetailArrayList);
//        Log.d("test", String.valueOf(dishesDetailArrayList));
        ListView listView = (ListView) view.findViewById(R.id.list_show);
        listView.setAdapter(dishesDetailAdapter);

        return view;
    }

    public void refresh(Dishes dishes) {
        dishesDetailArrayList.clear();
        dishesDetailArrayList.addAll(dishes.getCollections());
        dishesDetailAdapter.notifyDataSetChanged();
        Log.d("test", String.valueOf(dishesDetailArrayList));
    }

}
